home *** CD-ROM | disk | FTP | other *** search
/ El Mac 9 / El Mac 9.iso / Shareware / Demos / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Waves / Kill Waves < prev    next >
Encoding:
Text File  |  1996-01-29  |  4.4 KB  |  142 lines  |  [TEXT/IGR0]

  1. | WARNING: Routines in this file can kill wave files.
  2. |    See the warnings below. Make sure you understand them before using these procedures.
  3. |    NOTE: These functions works on waves in the current data folder only.
  4.  
  5. #pragma rtGlobals=1
  6.  
  7. #include <Strings as Lists>
  8. #include <Execute Cmd On List>
  9.  
  10. | KillMatchingWaves(matchStr, flags)
  11. |    matchStr is "*" for all waves or "wave*" for all waves whose name starts with "wave".
  12. |    flags is:
  13. |        bit 0: set to kill wave files (KillWaves/F)
  14. |    WARNING: This can kill wave files. Make sure you know what you are doing.
  15. |    NOTE: This function works on waves in the current data folder only.
  16. Function KillMatchingWaves(matchStr, flags)
  17.     String matchStr
  18.     Variable flags
  19.     
  20.     String cmdTemplate
  21.     
  22.     if (flags %& 1)
  23.         cmdTemplate = "KillWaves/Z/F %s"
  24.     else
  25.         cmdTemplate = "KillWaves/Z %s"
  26.     endif
  27.     ExecuteCmdOnQuotedList(cmdTemplate, WaveList(matchStr, ";", ""))
  28. End
  29.  
  30. | RemoveWavesFromGraph(graphName, matchStr)
  31. |    This is a building-block for RemoveWavesFromWindow.
  32. |    NOTE: This function will not work reliably if the graph contains waves from other than the current data folder.
  33. Function RemoveWavesFromGraph(graphName, matchStr)    
  34.     String graphName                        | name of a graph
  35.     String matchStr                        | "*" to remove all waves
  36.     
  37.     String wn
  38.     String wl
  39.     Variable i, offset, type
  40.     
  41.     DoWindow/F $graphName
  42.     if (V_flag)
  43.         wl = WaveList(matchStr, ";", "WIN:")            | list of waves in graph and in current data folder
  44.         i = 0
  45.         do
  46.             wn = WaveName(graphName,i,1)            | next Y wave in graph
  47.             if (strlen(wn) == 0)
  48.                 break                                        | all done
  49.             endif
  50.             offset = FindItemInList(wn, wl, ";", 0)
  51.             if (offset >=0)
  52.                 RemoveFromGraph $wn
  53.             else
  54.                 i += 1
  55.             endif
  56.         while (1)
  57.     endif
  58. End
  59.  
  60. | RemoveWavesFromTable(tableName, matchStr)
  61. |    This is a building-block for RemoveWavesFromWindow.
  62. |    NOTE: This function will not work reliably if the table contains waves from other than the current data folder.
  63. Function RemoveWavesFromTable(tableName, matchStr)
  64.     String tableName                        | name of a table
  65.     String matchStr                        | "*" to remove all waves
  66.     
  67.     String wn
  68.     String wl
  69.     Variable i, offset
  70.     
  71.     DoWindow/F $tableName
  72.     if (V_flag)
  73.         wl = WaveList(matchStr, ";", "WIN:")            | list of waves in table
  74.         i = 0
  75.         do
  76.             wn = WaveName(tableName,i,3)                | name of next column in table
  77.             if (strlen(wn) == 0)
  78.                 break                                        | all done
  79.             endif
  80.             wn = wn[0, strsearch(wn, ".", 0)-1]        | get rid of suffix (.x, .y)
  81.             if (CmpStr(wn[0], "'") == 0)                | remove single quotes if necessary
  82.                 wn = wn[1, strlen(wn)-2]
  83.             endif
  84.             offset = FindItemInList(wn, wl, ";", 0)
  85.             if (offset >=0)
  86.                 RemoveFromTable $wn.id
  87.             else
  88.                 i += 1
  89.             endif
  90.         while (1)
  91.     endif
  92. End
  93.  
  94. | RemoveWavesFromWindow(windowName, matchStr)
  95. |    Removes waves whose names match the matchStr parameter from the named graph or table window.
  96. |    NOTE: This function will not work reliably if the window contains waves from other than the current data folder.
  97. Function RemoveWavesFromWindow(windowName, matchStr)
  98.     String windowName
  99.     String matchStr                        | "*" to remove all waves
  100.     
  101.     DoWindow/F $windowName
  102.     if (V_flag)
  103.         if (WinType(windowName) == 1)            | this is a graph?
  104.             RemoveWavesFromGraph(windowName, matchStr)
  105.         endif
  106.         if (WinType(windowName) == 2)            | this is a table?
  107.             RemoveWavesFromTable(windowName, matchStr)
  108.         endif
  109.     endif
  110. End
  111.  
  112. | RemoveWavesFromWindows(winMatchStr, matchStr)
  113. |    Removes matching waves from matching windows.
  114. |    winMatchStr is "*" for all waves or "Graph*" for all waves whose name starts with "Graph".
  115. |    matchStr is "*" for all waves or "wave*" for all waves whose name starts with "wave".
  116. |    NOTE: This function will not work reliably if the windows contain waves from other than the current data folder.
  117. Function RemoveWavesFromWindows(winMatchStr, waveMatchStr)
  118.     String winMatchStr                    | "*" for all windows                    
  119.     String waveMatchStr                    | "*" to remove all waves
  120.     
  121.     String cmdTemplate
  122.     sprintf cmdTemplate, "RemoveWavesFromWindow(\"%%s\", \"%s\")", waveMatchStr
  123.     ExecuteCmdOnList(cmdTemplate, WinList(winMatchStr,";","WIN:3"))
  124. End
  125.  
  126. | KillAllWaves(flags)
  127. |    Optionally, removes all waves from all graphs and tables.
  128. |    Then kills all waves that are not in use.
  129. |    flags is:
  130. |        bit 0: set to kill wave files (KillWaves/F)
  131. |        bit 1: set to remove all waves from graphs and tables
  132. |    WARNING: This can kill wave files. Make sure you know what you are doing.
  133. |    NOTE: This function works on waves in the current data folder only.
  134. Function KillAllWaves(flags)
  135.     Variable flags
  136.     
  137.     if (flags %& 2)
  138.         RemoveWavesFromWindows("*", "*")
  139.     endif
  140.     KillMatchingWaves("*", flags)
  141. End
  142.